#include "factory.h"
int main(int argc,char *argv[])
{
    if(argc!=5)
    {
        printf("Usage:./server ip port threadnum quecapacity\n");
    } 
    factory_t fac;
    int threadnum=atoi(argv[3]);
    int quecapacity=atoi(argv[4]);
    //初始化工厂
    factory_init(&fac,threadnum,quecapacity);
    //启动线程池
    factory_start(&fac);
    //初始化socket
    int sockfd;
    tcp_init(&sockfd,argv[1],argv[2]);
    int newfd;
    pnode_t pnewnod;
    pque_t pque=&fac.que;
    while(1)
    {
        //这里不拿客户端地址
        newfd=accept(sockfd,NULL,NULL);
        pnewnod=(pnode_t)calloc(1,sizeof(node_t));
        pnewnod->newfd=newfd;
        pthread_mutex_lock(&pque->q_mutex);
        que_set(pque,pnewnod);
        pthread_mutex_unlock(&pque->q_mutex);
        pthread_cond_signal(&fac.cond);
    }
    return 0;
}

